package  com.lx.components.charts.dashboard.gaugeChart.utils
{
	import flash.display.Graphics;
	FLEX_TARGET_VERSION::flex4
	{
		import mx.graphics.SolidColorStroke;
	}
	FLEX_TARGET_VERSION::flex3
	{
		import mx.graphics.SolidColor;
	}
	import mx.graphics.Stroke;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import mx.graphics.IFill;
	import mx.charts.chartClasses.GraphicsUtilities;
	import mx.graphics.SolidColor;
	
	public class GraphicsUtil
	{
	
		public static function drawArc(g:Graphics, angleStart:Number,angleEnd:Number, color:Number, alpha:Number, diameter:Number):void {
		 	
		 	
			const SHADOW_INSET:Number = 0;

		 	
	      	var fCenterX:Number=diameter/2;
	      	var fCenterY:Number=diameter/2;
	      	var fRadius:Number=diameter/2;
	     
			// //trace("radius is " + fRadius);
			
			//fRadius=100;
			
			if(isNaN(fRadius)) return;
					
			var outerRadius:Number = fRadius/1.25;
			var innerRadius:Number = fRadius/1.55;
			var origin:Point = new Point();
			origin.x=fCenterX;
			origin.y=fCenterY;
			var angle:Number = (angleEnd) * Math.PI/180; //in radians
			var startAngle:Number = angleStart * Math.PI/180; //in radians
					
			FLEX_TARGET_VERSION::flex4
			{
				var stroke:SolidColorStroke = new SolidColorStroke();
				stroke.alpha=0;
				stroke.weight=0;
				stroke.color=0xFF0000;
				stroke.alpha=alpha;
				
				if (stroke && !isNaN(stroke.weight))
					outerRadius -= Math.max(stroke.weight/2,SHADOW_INSET);
				else
					outerRadius -= SHADOW_INSET;
			}
			FLEX_TARGET_VERSION::flex3
			{
				outerRadius -= Math.max(0,SHADOW_INSET);
			}
							
			outerRadius = Math.max(outerRadius, innerRadius);
			
			var rc:Rectangle = new Rectangle(origin.x - outerRadius,
											 origin.y - outerRadius,
											 2 * outerRadius, 2 * outerRadius);
			
			var sc:SolidColor=new SolidColor(color);
			sc.alpha=alpha;
			var fill:IFill = sc;
	
			
			var startPt:Point = new Point(
				origin.x + Math.cos(startAngle) * outerRadius,
				origin.y - Math.sin(startAngle) * outerRadius);
	
			var endPt:Point = new Point(
				origin.x + Math.cos(startAngle + angle) * outerRadius,
				origin.y - Math.sin(startAngle + angle) * outerRadius);
	
			g.moveTo(endPt.x, endPt.y);
	
			FLEX_TARGET_VERSION::flex4
			{
				fill.begin(g,rc, null);
			}
			FLEX_TARGET_VERSION::flex3
			{
				fill.begin(g,rc);
			}
			
	
			//GraphicsUtilities.setLineStyle(g, stroke);
	
			if (innerRadius == 0)
			{
				g.lineTo(origin.x, origin.y);
				g.lineTo(startPt.x, startPt.y);
			}
			else
			{
				var innerStart:Point = new Point(
					origin.x + Math.cos(startAngle + angle) * innerRadius,
					origin.y - Math.sin(startAngle + angle) * innerRadius);
	
				g.lineTo(innerStart.x, innerStart.y);			
	
				//GraphicsUtilities.setLineStyle(g, stroke);
				GraphicsUtilities.drawArc(g, origin.x, origin.y,
										  startAngle + angle, -angle,
										  innerRadius, innerRadius, true);
	
				//GraphicsUtilities.setLineStyle(g, stroke);
				g.lineTo(startPt.x, startPt.y);
			}
	
			//GraphicsUtilities.setLineStyle(g, stroke);
	
			GraphicsUtilities.drawArc(g, origin.x, origin.y,
									  startAngle, angle,
									  outerRadius, outerRadius, true);
	
			fill.end(g);
		}
	}
}